package com.neuedu.cockpit.service.impl;

import java.util.List;

import com.neuedu.cockpit.common.Encode;
import com.neuedu.cockpit.domain.HmControlLog;
import com.neuedu.cockpit.mapper.HmControlLogMapper;
import com.neuedu.cockpit.service.IHmControlLogService;
import com.neuedu.common.exception.base.BaseException;
import com.neuedu.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * 车辆操控日志Service业务层处理
 * 
 * @author neuedu
 * @date 2024-04-30
 */
@Service
public class HmControlLogServiceImpl implements IHmControlLogService
{
    @Autowired
    private HmControlLogMapper hmControlLogMapper;

    /**
     * 查询车辆操控日志
     * 
     * @param id 车辆操控日志主键
     * @return 车辆操控日志
     */
    @Override
    public HmControlLog selectHmControlLogById(Long id)
    {
        return hmControlLogMapper.selectHmControlLogById(id);
    }

    /**
     * 查询车辆操控日志列表
     * 
     * @param hmControlLog 车辆操控日志
     * @return 车辆操控日志
     */
    @Override
    public List<HmControlLog> selectHmControlLogList(HmControlLog hmControlLog)
    {
        hmControlLog.setOperaContent(Encode.encodeStr(hmControlLog.getOperaContent()));
        List<HmControlLog> lt = hmControlLogMapper.selectHmControlLogList(hmControlLog);
        if(!CollectionUtils.isEmpty(lt)) {
            for(HmControlLog cl : lt) {
                cl.setUserName(hmControlLogMapper.selectUserName(cl.getUserId()));
            }
        }
        return lt;
    }

    /**
     * 新增车辆操控日志
     * 
     * @param hmControlLog 车辆操控日志
     * @return 结果
     */
    @Override
    public int insertHmControlLog(HmControlLog hmControlLog)
    {
        if(StringUtils.isEmpty(hmControlLog.getOperaType())) {
            throw new BaseException("操控类型不能为空");
        }
        return hmControlLogMapper.insertHmControlLog(hmControlLog);
    }

    /**
     * 修改车辆操控日志
     * 
     * @param hmControlLog 车辆操控日志
     * @return 结果
     */
    @Override
    public int updateHmControlLog(HmControlLog hmControlLog)
    {
        return hmControlLogMapper.updateHmControlLog(hmControlLog);
    }

    /**
     * 批量删除车辆操控日志
     * 
     * @param ids 需要删除的车辆操控日志主键
     * @return 结果
     */
    @Override
    public int deleteHmControlLogByIds(Long[] ids)
    {
        return hmControlLogMapper.deleteHmControlLogByIds(ids);
    }

    /**
     * 删除车辆操控日志信息
     * 
     * @param id 车辆操控日志主键
     * @return 结果
     */
    @Override
    public int deleteHmControlLogById(Long id)
    {
        return hmControlLogMapper.deleteHmControlLogById(id);
    }
}
